/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package popups;

/**
 *
 * @author icdev
 */
import PCR.MainFrame;
import components.shape.Shape;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;

public class ToolReplaceCommander extends MouseAdapter {

    Integer[] pos = {300, 200, 100};
    int count = 0;
    MainFrame frm = (MainFrame) java.awt.Window.getWindows()[0];
    DefaultTableModel smearsModel;
    DefaultTableModel dimersModel;
    DefaultTableModel bandsModel;
    DefaultTableModel houseKeepingModel;
    DefaultTableModel proteinModel;
    JButton b;

    public void setDimersModel(DefaultTableModel dtm) {
        dimersModel = dtm;
    }

    public void setSmearsModel(DefaultTableModel dtm) {
        smearsModel = dtm;
    }

    public void setBandsModel(DefaultTableModel dtm) {
        bandsModel = dtm;
    }

    public void setHouseKeepingModelModel(DefaultTableModel dtm) {
        houseKeepingModel = dtm;
    }

    public void setProteinModel(DefaultTableModel dtm) {
        proteinModel = dtm;
    }
    String toolTitle;

    public void setToolTitle(String str) {
        toolTitle = str;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        try {
            if (e.getClickCount() == 2) {
                JButton curBtn = (JButton) e.getSource();
                if (toolTitle.equals("Smears")) {
                    SmearAction(curBtn);
                } else if (toolTitle.equals("Bands")) {
                    BandAction(curBtn);
                } else if (toolTitle.equals("Dimers")) {
                    DimerAction(curBtn);
                } else if (toolTitle.equals("HouseKeepings")) {
                    houseKeepingAction(curBtn);
                } else if (toolTitle.equals("Proteins")) {
                    ProteinAction(curBtn);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /// Write here Any aCtions 
    private void BandAction(JButton PressedBtn) {
        String image = (String) bandsModel.getValueAt(Integer.parseInt(PressedBtn.getAccessibleContext().getAccessibleDescription()), 1);
        Shape band = frm.getSeletedShape();
        Icon icn = new javax.swing.ImageIcon("resources/bands/" + image);
        Image img = ((ImageIcon) icn).getImage();
        ImageIcon icon = new ImageIcon(img.getScaledInstance(120, 25, Image.SCALE_AREA_AVERAGING));
        band.setImage(icon);
        frm.getSelectedWorkArea().getBandsPanel().repaint();
    }

    private void SmearAction(JButton PressedBtn) {
        String image = (String) smearsModel.getValueAt(Integer.parseInt(PressedBtn.getAccessibleContext().getAccessibleDescription()), 1);
        Shape smear = frm.getSeletedShape();
        Icon icn = new javax.swing.ImageIcon("resources/smears/" + image);
        Image img = ((ImageIcon) icn).getImage();
        ImageIcon icon = new ImageIcon(img.getScaledInstance(120, 25, Image.SCALE_AREA_AVERAGING));
        smear.setImage(icon);
        frm.getSelectedWorkArea().getBandsPanel().repaint();
        frm.setSelectedShape(smear);
    }

    private void DimerAction(JButton PressedBtn) {
        String image = (String) dimersModel.getValueAt(Integer.parseInt(PressedBtn.getAccessibleContext().getAccessibleDescription()), 1);
        Shape dimer = frm.getSeletedShape();
        Icon icn = new javax.swing.ImageIcon("resources/dimers/" + image);
        Image img = ((ImageIcon) icn).getImage();
        ImageIcon icon = new ImageIcon(img.getScaledInstance(120, 25, Image.SCALE_AREA_AVERAGING));
        dimer.setImage(icon);
        frm.getSelectedWorkArea().getBandsPanel().repaint();
        frm.setSelectedShape(dimer);
    }

    private void ProteinAction(JButton PressedBtn) {
        String image = (String) proteinModel.getValueAt(Integer.parseInt(PressedBtn.getAccessibleContext().getAccessibleDescription()), 1);
        Shape protein = frm.getSeletedShape();
        Icon icn = new javax.swing.ImageIcon("resources/proteins/" + image);
        Image img = ((ImageIcon) icn).getImage();
        ImageIcon icon = new ImageIcon(img.getScaledInstance(120, 25, Image.SCALE_AREA_AVERAGING));
        protein.setImage(icon);
        frm.getSelectedWorkArea().getBandsPanel().repaint();
        frm.setSelectedShape(protein);
    }

    private void houseKeepingAction(JButton PressedBtn) {
        String image = (String) houseKeepingModel.getValueAt(Integer.parseInt(PressedBtn.getAccessibleContext().getAccessibleDescription()), 1);
        Shape houseKeeping = frm.getSeletedShape();
        Icon icn = new javax.swing.ImageIcon("resources/housekeepings/" + image);
        Image img = ((ImageIcon) icn).getImage();
        ImageIcon icon = new ImageIcon(img.getScaledInstance(120, 25, Image.SCALE_AREA_AVERAGING));
        houseKeeping.setImage(icon);
        frm.getSelectedWorkArea().getBandsPanel().repaint();
        frm.setSelectedShape(houseKeeping);
    }
}
